<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="Cache" content="no-cache">
<meta http-equiv="expires" content="0"> 
<meta name="viewport" content ="width=device-width, initial-scale=1">
<%@ include file="JQMStyle.jsp"%>
<script>
$(document).ready(function(){
	$("#barcode").focus();

})
document.onkeyup = BSkeyUp; 

function BSkeyUp(e){
	var ieKey = window.event ? e.keyCode : e.which;
	 if (ieKey==13){
	   if (e.target.id=="barcode"){
	       var barcode =$("#barcode").val();
	       e.returnValue=false;
	       if (barcode != ""){
	    	   checkSearch();
	       }
	   } 
	 } 
} 
function clearProduct(){
	$("#barcode").focus();
	$("#barcode").val("");
	
    $("#products").hide();
    
    $('#productBody tr').each(function () {                
        $(this).remove();
    });

}
function checkSearch(){
	var barcode = $.trim($("#barcode").val());
	if (barcode.length == 12){
		$("#quantity").val( 1);
		$("#barcodeHidden").val(barcode);
		addOrder();
    } else {
		renderPopup("查询错误","条码错误");
		$("#barcode").focus();
    }
}

function addOrder(){
	
	if ($.trim($("#barcodeHidden").val()).length == 12){
		var barcode = $("#barcodeHidden").val();
		var quantity = $("#quantity").val();
		var orderMode = $("#orderMode").val();

		$.mobile.loading("show",{ theme: "b", text: "正在加载数据", textonly: false});
		var params="formBean.orderMode="+orderMode+"&formBean.barcode=" + barcode+ "&formBean.quantity=" + quantity+"&formBean.storeId=" + $("#storeId").val();

		$.post('<%=request.getContextPath()%>/action/ipadJSON!orderByBarcode4Pandian', params, 
		function(result) {
			$.mobile.loading("hide");
			if (result.returnCode != 2) {
				$("#msg").html(result.message);
				$("#remBtnDiv").hide();
			} else {
				$("#msg").html(result.returnValue.product);
				$("#img").attr("src",result.returnValue.imgURL);
				$("#remBtnDiv").show();				
			}

			$("#barcode").val("");
			$("#barcode").focus();
			$("#quantity").val( 1);			
		}, 'JSON');
		
	}
}

function deductOrder(){
	if ($.trim($("#barcodeHidden").val()).length >= 12){
		var barcode = $("#barcodeHidden").val();
		var quantity = -1*$("#quantity").val();
		
		$.mobile.loading("show",{ theme: "b", text: "正在加载数据", textonly: false});
		var params="formBean.barcode=" + barcode+ "&formBean.quantity="+ quantity +"&formBean.storeId=" + $("#storeId").val();

		$.post('<%=request.getContextPath()%>/action/ipadJSON!orderByBarcode4Pandian', params, 
		function(result) {
			$.mobile.loading("hide");
			if (result.returnCode != 2) {
				$("#msg").html(result.message);
			} else {
				$("#msg").html(result.returnValue.product);
				renderPopup("提示","退订成功");
			}
				
			$("#barcode").val("");
			$("#barcode").focus();
			$("#quantity").val( 1);

		}, 'JSON');
		
	} else {
		renderPopup("查询错误","条码错误");
		$("#barcode").focus();
	}
}


</script>
</head>
<body>
<!-- 按照品牌汇总的 MyOrder 汇总 -->
	<div id="myOrder" data-role="page">
		<script>
		    
		</script>
		<jsp:include  page="MobileHeader.jsp"/>

		<div  data-role="content" class="content">
		
				<table>
				    <tr>
						<td><label for="productCode">条码: </label></td> 
						<td><input id="barcode" name="barcode" placeholder="扫描条码"/></td>
						<td>
							<select id="storeId" name="storeId">
								<option value="1"  <s:if test="#session.HQ_SESSION_INFO_ORDER_STORE_ID ==1">selected</s:if>>濛阳</option>
								<option value="2" <s:if test="#session.HQ_SESSION_INFO_ORDER_STORE_ID ==2">selected</s:if>>质量问题</option>
								<option value="13"  <s:if test="#session.HQ_SESSION_INFO_ORDER_STORE_ID ==13">selected</s:if>>禧乐</option>
							</select>
						</td>
						<td><select id="orderMode" name="orderMode"><option value="2">单件</option><option value="1">齐码</option></select></td>
					</tr>

				</table>

				<div id="msg" style="display:show">
						
				</div>
				<div id="remBtnDiv" style="display:none">
				      <table>
				         <tr>
				            <td width="5%"><input type="hidden" id="barcodeHidden" name="barcodeHidden"/>
				        		<input type="number" id="quantity"  onfocus="this.select();" pattern="[0-9]*"/></td>
				            <td> <input name='remBtn' type='button' value='加订' data-mini='true'  data-inline='true' onclick='addOrder();'/>
						         <input name='remBtn' type='button' value='退订' data-mini='true'  data-inline='true' onclick='deductOrder();'/>
				            </td>
				            <td>
				            </td>
				         </tr>
				         <tr>
				            <td colspan="3"><img id="img" src="" width="150" height="150" alt="没有图片"/></td>
				         </tr>
				      </table>


				</div>				
		</div>


        <jsp:include  page="MobileFooter.jsp"/>
		<jsp:include  page="Popup.jsp"/>

	</div>

</body>
</html>